package org.spring.blog.controller.admin;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.spring.blog.response.ResponseResult;
import org.spring.blog.response.ResponseState;
import org.spring.blog.service.IWebSizeInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@PreAuthorize("@permission.admin()")
@RestController
@RequestMapping("/admin/web_size_info")
public class WebSizeInfoAdminApi {
    final
    IWebSizeInfoService webSizeInfoService;

    public WebSizeInfoAdminApi(IWebSizeInfoService webSizeInfoService) {
        this.webSizeInfoService = webSizeInfoService;
    }

    /**
     * 获取网站描述
     *
     * @return 自定义返回对象
     */
    @ApiOperation("获取网站描述")
    @ApiResponses({
            @ApiResponse(code = ResponseState.no_power_code, message = ResponseState.no_power_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
            @ApiResponse(code = ResponseState.failed_code, message = ResponseState.failed_message),
    })
    @GetMapping("/seo")
    public ResponseResult getSeoInfo() {
        return webSizeInfoService.getSeoInfo();
    }

    /**
     * 设置网站描述
     *
     * @param keywords    关键字
     * @param description 网站描述
     * @return 自定义返回对象
     */
    @ApiOperation("设置网站描述")
    @ApiResponses({
            @ApiResponse(code = ResponseState.no_power_code, message = ResponseState.no_power_message),
            @ApiResponse(code = ResponseState.input_data_is_empty_code, message = ResponseState.input_data_is_empty_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @PutMapping("/seo")
    public ResponseResult putSeoInfo(@RequestParam("keywords") String keywords, @RequestParam("description") String description) {
        return webSizeInfoService.putSeoInfo(keywords, description);
    }

    /**
     * 获取网站标题
     *
     * @return 自定义返回对象
     */
    @ApiOperation("获取网站标题")
    @ApiResponses({
            @ApiResponse(code = ResponseState.no_power_code, message = ResponseState.no_power_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @GetMapping("/title")
    public ResponseResult getWebSizeTitle() {
        return webSizeInfoService.getWebSizeTitle();
    }

    /**
     * 更新网站标题
     *
     * @return 自定义返回对象
     */
    @ApiOperation("更新网站标题")
    @ApiResponses({
            @ApiResponse(code = ResponseState.no_power_code, message = ResponseState.no_power_message),
            @ApiResponse(code = ResponseState.input_data_is_empty_code, message = ResponseState.input_data_is_empty_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @PutMapping("/title")
    public ResponseResult updateWebSizeTitle(@RequestParam("title") String _title) {
        return webSizeInfoService.updateWebSizeTitle(_title);
    }

    /**
     * 获取网站浏览量
     *
     * @return 自定义返回对象
     */
    @ApiOperation("获取网站浏览量")
    @ApiResponses({
            @ApiResponse(code = ResponseState.no_power_code, message = ResponseState.no_power_message),
            @ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message),
    })
    @GetMapping("/view_count")
    public ResponseResult getWebSizeViewCount() {
        return webSizeInfoService.getWebSizeViewCount();
    }
}
